from django.shortcuts import render
from django.views.decorators.clickjacking import xframe_options_sameorigin

from dashboard import k8s
from dashboard.details import DeploymentDetailsInfo


# Create your views here.


@k8s.self_login_required
def deployment(request):
    return render(request, "workload/deployment.html")


@k8s.self_login_required
def daemonset(request):
    return render(request, "workload/daemonset.html")


@k8s.self_login_required
def statefulset(request):
    return render(request, "workload/statefulset.html")


@k8s.self_login_required
def pods(request):
    return render(request, "workload/pods.html")


@k8s.self_login_required
def pods_create(request):
    return render(request, "workload/pods_create.html")


@k8s.self_login_required
def deployment_create(request):
    return render(request, "workload/deployment_create.html")


@k8s.self_login_required
def deployment_details(request):
    namespace = request.GET.get('namespace')
    name = request.GET.get('name')
    api = DeploymentDetailsInfo(request=request)
    dp_info = api.deployment_info()
    return render(request, "workload/deployment_details.html",
                  {'namespace': namespace, 'name': name, 'dp_info': dp_info})


@k8s.self_login_required
def daemonset_create(request):
    return render(request, "workload/daemonset_create.html")


@k8s.self_login_required
def statefulset_create(request):
    return render(request, "workload/statefulset_create.html")


@xframe_options_sameorigin
@k8s.self_login_required
def container_log(request):
    name = request.GET.get('name')
    namespace = request.GET.get('namespace')
    return render(request, "container-log.html", {'name': name, 'namespace': namespace})


@xframe_options_sameorigin
@k8s.self_login_required
def web_ssh(request):
    name = request.GET.get('name')
    namespace = request.GET.get('namespace')
    return render(request, "workload/webssh.html", {'name': name, 'namespace': namespace})
